package com.ljh.bigevent.controller;

import com.ljh.bigevent.pojo.Result;
import com.ljh.bigevent.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename=file.getOriginalFilename();
        //保证文件名字是唯一的，防止被覆盖
        String filename= UUID.randomUUID()+originalFilename.substring(originalFilename.lastIndexOf("."));
        /*file.transferTo(new File("C:\\Users\\ASUS\\Desktop\\bigevent\\"+filename));*/
        String url=AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
